#取得顶层目录
TOPDIR = $(shell pwd)

EXECS =  TPSIndex_test

.PHONY : everything deps objs clean veryclean rebuild

everything: $(EXECS)

LIBS := -lpthread

CC  = gcc
CXX = g++
LD  = g++

###define archive option
ARCHIVE  = ar


CFLAGS := -Wall -O2

INCDIR = $(TOPDIR)
#INCDIR += ../../
CFLAGS += -I$(INCDIR)

CFLAGS += -L$(INCDIR)

CXXFLAGS := $(CFLAGS)
LDFLAGS += -std=c++11 -Wall -Wextra -g
#-MD -DLINUX -DUSE_LIB -D_DEBUG_LOG

#定义其他变量
RM-F := rm -f
LIB		:= /usr/lib64
#可以是 f （普通文件）、d （目录）、l （符号链接）等
LIBDIRS		:= $(shell find $(LIB))
# define the C libs
LIBS := $(patsubst %,-L%, $(LIBDIRS:%/=%))
#使用“$(wildcard *.c)”来获取工作目录下的所有的.c文件列表	 
TPSIndextest_HEADER := $(wildcard $(TOPDIR)/*.h) \
		    $(wildcard $(TOPDIR)/src/*.h) \
			 $(wildcard $(TOPDIR)/../*.h)

TPSIndextest_SOURCE := $(wildcard $(TOPDIR)/*.cpp) \
			$(wildcard $(TOPDIR)/../*.cpp)\
			$(wildcard $(TOPDIR)/../*.c)

#patsubst 替换为目标后缀名
OBJS := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(TPSIndex_SOURCE)))
DEPS := $(patsubst %.o,%.d,$(OBJS))
MISSING_DEPS := $(filter-out $(wildcard $(DEPS)),$(DEPS))
MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.c,$(MISSING_DEPS)) \
$(patsubst %.d,%.cpp,$(MISSING_DEPS)))


TestObj := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(TPSIndextest_SOURCE))) 
TestDEPS := $(patsubst %.o,%.d,$(TestObj))

deps : $(DEPS) $(TestDEPS)
objs : $(OBJS) $(TestObj)


clean :
	@$(RM-F) *.o $(OBJS) $(TestObj)
	@$(RM-F) *.d $(DEPS) $(TestDEPS)

veryclean: clean
	@$(RM-F) $(EXECS)

rebuild: veryclean everything

ifneq ($(MISSING_DEPS),)
$(MISSING_DEPS) :
	@$(RM-F) $(patsubst %.d,%.o,$@)
endif

-include $(DEPS) $(TestDEPS)


TPSIndex_test : $(OBJS) $(TestObj)
	$(LD) -o FTCPG_Local -I$(INCDIR) -I/root/tcp_gateway  $(TestObj) $(OBJS) -L/usr/local/mysql/lib /root/tcp_gateway/libFastUdx.a -lpthread -lrt -lsqlite3 -lmysqlclient
	 


